<template>
  <view class="flex-1 flex items-center">
    <view class="flex-1 ">
      <u-input class="flex-1" v-model="value" :disabled="disabled" :placeholder="placeholder" type="text"
        :input-align="inputAlign" />
    </view>

    <view class="flex items-center">
      <u-icon name="/static/address/icon_dz.png" size="36" class="mr-l" @click="addressVisible = !addressVisible"></u-icon>
    </view>
    <AddressChoose v-model:visible="addressVisible" @address-choose="addressChoose"></AddressChoose>
  </view>
</template>

<script>
import AddressChoose from '../address-choose/AddressChoose.vue'
export default {
  name: "yer-address",
  components: {
    AddressChoose
  },
  props: {
    disabled: Boolean,
    defaultValue: "", //默认显示的字典，传字典的代码项
    inputAlign: {
      type: String,
      default: "left",
    }, //input内容对齐方式三种：left  center  right  默认left
    placeholder: {
      type: String,
      default: "请选择",
    }
  },
  emits: ["update:dzmc", "update:dzbm"],
  data() {
    return {
      value: "", //字典展示的值，对应的是字典名称
      addressVisible: false // 
    }
  },
  methods: {
    clear() {
      this.value = "";
    },
    addressChoose(e) {
      // console.log(e);
      let dzmc = (e.DZYS_DZXXC.indexOf(e.DZYSMC)>-1)? e.DZYS_DZXXC : (e.DZYS_DZXXC+e.DZYSMC)

      this.value = dzmc
      this.$emit("update:dzbm", e.ST_DZYSID);
      this.$emit("update:dzmc", dzmc);
      // uni.showModal({
      //   title: '提示',
      //   content: `是否绑定当前地址（${props.item.DZMCBT}）至${e.DZYS_DZXXC}`,
      //   success: async (r) => {
      //     if (r.confirm) {
      //       // 绑定地址
      //       const res = await updateStDzysid({
      //         bh: props.item.BH,
      //         stDzysid: e.ST_DZYSID
      //       })
      //       // 绑定成功后 直接页面赋值 不刷新页面
      //       props.item.ST_DZYSID = e.ST_DZYSID
      //     }

      //   }
      // })
    }
  },
  watch: {
    // value: function (newVal, oldVal) {
    //   this.$emit("update:modelValue", newVal);
    //   this.$emit("input", newVal);
    // },
    defaultValue: {
      immediate: true,
      handler: function (newVal, oldVal) {
        if (newVal == 0) {
          this.value = newVal + "";
        } else {
          this.value = newVal;
        }
      },
    }
  },
};
</script>

<style>

</style>
